package com.mock.action.organisation.team;

import java.util.List;

import com.mock.dao.DepartmentDao;
import com.mock.dao.DirectorateDao;
import com.mock.dao.TeamDao;
import com.mock.dao.impl.CountryDaoImpl;
import com.mock.dao.impl.DepartmentImpl;
import com.mock.dao.impl.DirectorateDaoImp;
import com.mock.dao.impl.TeamDaoImpl;
import com.mock.model.Country;
import com.mock.model.Department;
import com.mock.model.Team;
import com.opensymphony.xwork2.ActionSupport;

public class EditTeamAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 5467860198386152157L;
	
	private TeamDao teamDao = new TeamDaoImpl();
	private Team teamBean;
	private Long teamId = -1L;
	private String name;
	private String shortDescription;
	private String fullDescription;
	private Long contactId;
	private String addressLine1;
	private String addressLine2;
	private String addressLine3;
	private String postcode;
	private String town;
	private String county;
	private Long countryId;
	private String phonenumber;
	private String fax;
	private String email;
	private String webAddress;
	private boolean active;
	private Long contactIden;
	private List<Country> countries;
	private Long departmentId;
	private Long directorateId;
	private String tab;
	
	public String execute() {
		countries = new CountryDaoImpl().getAllCountry();
		DepartmentDao departmentDao = new DepartmentImpl();
		try {
			departmentId = teamDao.getById(Team.class, teamId).getDepartment().getId();
			directorateId = departmentDao.getById(Department.class, departmentId).getDirectorate().getDirectorateId();
		}catch (Exception e) {
			System.out.println("Error Get Id Directorate Or Department : "+e.getMessage());
			return ERROR;
		}
		return SUCCESS;
	}
	
	public String updateTeam() {
		Team team = teamDao.getById(Team.class, teamId);
		team.setName(name);
		team.setShortDescription(shortDescription);
		team.setAddressLine1(addressLine1);
		team.setAddressLine2(addressLine2);
		team.setAddressLine3(addressLine3);
		team.setPostcode(postcode);
		team.setTown(town);
		Country country = new CountryDaoImpl().getById(countryId);
		team.setCountry(country);
		team.setPhonenumber(phonenumber);
		teamDao.update(team);
		return SUCCESS;
	}
	
	

	@Override
	public void validate() {
		if ("".equalsIgnoreCase(name)) {
			System.out.println("name is null");
			addActionError("Name can not be null");
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Team getTeamBean() {
		if (teamId != -1L) {
			teamBean = teamDao.getById(Team.class, teamId);
		}
		return teamBean;
	}

	public void setTeamBean(Team teamBean) {
		this.teamBean = teamBean;
	}

	public String getShortDescription() {
		return shortDescription;
	}

	public void setShortDescription(String shortDescription) {
		this.shortDescription = shortDescription;
	}

	public String getFullDescription() {
		return fullDescription;
	}

	public void setFullDescription(String fullDescription) {
		this.fullDescription = fullDescription;
	}

	public Long getContactId() {
		return contactId;
	}

	public Long getTeamId() {
		return teamId;
	}

	public void setTeamId(Long teamId) {
		this.teamId = teamId;
	}

	public void setContactId(Long contactId) {
		this.contactId = contactId;
	}

	public String getAddressLine1() {
		return addressLine1;
	}

	public void setAddressLine1(String addressLine1) {
		this.addressLine1 = addressLine1;
	}

	public String getAddressLine2() {
		return addressLine2;
	}

	public void setAddressLine2(String addressLine2) {
		this.addressLine2 = addressLine2;
	}

	public String getAddressLine3() {
		return addressLine3;
	}

	public void setAddressLine3(String addressLine3) {
		this.addressLine3 = addressLine3;
	}

	public String getPostcode() {
		return postcode;
	}

	public void setPostcode(String postcode) {
		this.postcode = postcode;
	}

	public String getTown() {
		return town;
	}

	public void setTown(String town) {
		this.town = town;
	}

	public String getCounty() {
		return county;
	}

	public void setCounty(String county) {
		this.county = county;
	}

	public Long getCountryId() {
		return countryId;
	}

	public void setCountryId(Long countryId) {
		this.countryId = countryId;
	}

	public String getPhonenumber() {
		return phonenumber;
	}

	public void setPhonenumber(String phonenumber) {
		this.phonenumber = phonenumber;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getWebAddress() {
		return webAddress;
	}

	public void setWebAddress(String webAddress) {
		this.webAddress = webAddress;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public Long getContactIden() {
		return contactIden;
	}

	public void setContactIden(Long contactIden) {
		this.contactIden = contactIden;
	}

	public List<Country> getCountries() {
		return countries;
	}

	public void setCountries(List<Country> countries) {
		this.countries = countries;
	}

	public Long getDepartmentId() {
		return departmentId;
	}

	public void setDepartmentId(Long departmentId) {
		this.departmentId = departmentId;
	}

	public Long getDirectorateId() {
		return directorateId;
	}

	public void setDirectorateId(Long directorateId) {
		this.directorateId = directorateId;
	}
	
	

	public String getTab() {
		return tab;
	}

	public void setTab(String tab) {
		this.tab = tab;
	}

}
